package cn.edu.tju.elm.mapper;

import cn.edu.tju.elm.dto.ComplainCreateDTO;
import cn.edu.tju.elm.dto.ComplainResponseDTO;
import cn.edu.tju.elm.dto.ComplainUpdateDTO;
import cn.edu.tju.elm.model.Complain;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.List;

/**
 * ClassName: ComplainMapper
 * Package: cn.edu.tju.elm.mapper
 * Description: 投诉Mapper，用于实体和DTO之间的转换
 *
 * @Author System
 * @Create 2025/10/31
 * @Version 1.0
 */
@Mapper(componentModel = "spring")
public interface ComplainMapper {

    /**
     * 将CreateDTO转换为实体
     * 注意：order, customer, business需要在service层设置
     */
    @Mapping(target = "order", ignore = true)
    @Mapping(target = "customer", ignore = true)
    @Mapping(target = "business", ignore = true)
    @Mapping(target = "state", constant = "0")
    @Mapping(target = "businessReply", ignore = true)
    @Mapping(target = "adminReply", ignore = true)
    Complain createDtoToComplain(ComplainCreateDTO dto);

    /**
     * 将实体转换为ResponseDTO
     */
    @Mapping(target = "orderId", source = "order.id")
    @Mapping(target = "customerId", source = "customer.id")
    @Mapping(target = "customerUsername", source = "customer.username")
    @Mapping(target = "businessId", source = "business.id")
    @Mapping(target = "businessName", source = "business.businessName")
    ComplainResponseDTO complainToResponseDTO(Complain complain);

    /**
     * 将实体列表转换为ResponseDTO列表
     */
    List<ComplainResponseDTO> complainsToResponseDTOs(List<Complain> complains);

    /**
     * 将UpdateDTO转换为实体（用于部分更新）
     */
    @Mapping(target = "order", ignore = true)
    @Mapping(target = "customer", ignore = true)
    @Mapping(target = "business", ignore = true)
    Complain updateDtoToComplain(ComplainUpdateDTO dto);
}

